/* -----------------------------------------------------
 iCompose
 Note.m
 
 Created by Team: THE BEARD on 18/10/09
 Members who contributed to this file:
 1. Ethan Holmes
 2. Bobby Luk
 
 List of changes to previous member:
 Version 1:
 Oct 25, 2009 (Bobby)
 - Added play function
 Oct 31, 2009 (Ethan)
 - removed play function
 - implemented initRest method
 - implemented Encode / Decode methods
 Nov 2, 2009 (Ethan)
 - revised initNote method
 
 Simon Fraser University, 2009.
 ----------------------------------------------------- */

#import "Note.h"

@implementation Note

@synthesize noteBeat;
@synthesize notePitch;

/*
 Initializes the notes member variables to the correct beat.
 The beat corresponds to the length of the note in time.
 The values are as follows: [noteBeat = What type of note duration-wise]
 
 0 = rest (no sound)
 0.5 = eighth note
 1 = quarter note
 1.5 = dotted quarter note, duration is (eighth note + quarter note)
 2 = half note
 3 = dotted half note, duration is (half note + quarter note)
 4 = whole note
 
 The pitch is the frequency of sound. 
 Mapping is shown below: [notePitch = What type of note pitch-wise]

 100 = Middle C natural
 101 = C sharp, D flat
 102 = D natural
 103 = D sharp, E flat
 104 = E natural, F flat
 105 = F natural
 106 = F sharp, G flat
 107 = G natural
 108 = G sharp, A flat
 109 = A natural
 110 = A sharp, B flat
 111 = B natural, C flat
 112 = C natural
 113 = C sharp, D flat
 114 = D natural
 115 = D sharp, E flat
 116 = E natural, F flat
 117 = F natural
 118 = F sharp, G flat
 119 = G natural,
 120 = G sharp, A flat
 121 = A natrual
 */

-(id)initWholeNote {
	if (self = [super init]) {
		noteBeat = 4.0;
		notePitch = 0;
	}
	return self;
}

-(id)initHalfNote {
	if (self = [super init]) {
		noteBeat = 2.0;
		notePitch = 0;
	}
	return self;
}

-(id)initQuarterNote {
	if (self = [super init]) {
		noteBeat = 1.0;
		notePitch = 0;
	}
	return self;
}

-(id)initEighthNote {
	if (self = [super init]) {
		noteBeat = 0.5;
		notePitch = 0;
	}
	return self;
}


-(id)initWithCoder:(NSCoder*)coder {
	noteBeat = [coder decodeFloatForKey:@"noteBeat"];
	notePitch = [coder decodeIntForKey:@"notePitch"];
	return self;
}

-(void)encodeWithCoder:(NSCoder*)encoder {
	[encoder encodeFloat:noteBeat  forKey:@"noteBeat"];
	[encoder encodeInt:notePitch  forKey:@"notePitch"];
}

@end
